<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { equipApi } from '@/api/controller'
  import { ToastSuccess, ToastWarning, Toastloading } from '@/utils/public';
  import updateForm from './updateForm.vue';
import { ElMessageBox } from 'element-plus';
  const updateFormRef = ref()
  const action = reactive({
    dialogFormVisible:false,
    disabled:false,
    title:'',
    gameList:[] as Array<any>,
    list:[] as Array<any>
  })
  const listQuery = reactive({
    pool_one_id:'',
  })
  const openForm = (row:any = {})=>{
    updateFormRef.value.openDialog(row)
  }
  const handleDelete = (row:any = {})=>{
    const { id=0 } = row
    if(!id) return ToastWarning('缺少id')
    ElMessageBox.confirm("确定删除此货架吗?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(async () => {
      const loading = Toastloading();
      equipApi.pollTwoDel({id}).then(()=>{
        ToastSuccess("删除成功!");
        loading.close();
        getList();
      }).catch(()=>{
        loading.close();
      })
    }).catch(() => {});
  }
  const getList = async()=>{
    const loading = Toastloading()
    const res = await equipApi.poolTwoList(listQuery)
    loading.close()
    const { data=[] } = res || {}
    action.list = data
  }
  // onMounted(() => {
  //   getGameIdList()
  //   getList() d
  // })
  const openDialog = async(query:any = {})=> {
    const {
      item_name='',
      gameList=[],
      id
    } = query
    action.title = `${item_name}二级礼物池`
    action.gameList = gameList
    listQuery.pool_one_id = id
    await getList()
    action.dialogFormVisible = true
  }
  defineExpose({
    openDialog
  })
</script>

<template>
  <div>
    <el-dialog
      top="5vh"
      class="xm-dialog input-width"
      v-model="action.dialogFormVisible"
      width="85%"
      :title="action.title">
      <div class="xm-headTab">
        <div class="labelBox">
          <div class="labelItem">
            <el-button type="primary" @click="openForm">新增</el-button>
          </div>
        </div>
      </div>
      <el-table
        class="xm-main xm-TableCenter"
        :data="action.list"
        border>
        <el-table-column min-width="120" prop="game_id" label="游戏ID" />
        <el-table-column min-width="120" prop="pool_one_id" label="一级礼物池id" />
        <el-table-column min-width="120" prop="id" label="二级礼物池ID" />
        <el-table-column min-width="140" prop="man_equip_id" label="男装备id" />
        <el-table-column min-width="140" prop="man_equip_name" label="男装备名称" />
        <el-table-column min-width="140" prop="girl_equip_id" label="女装备id" />
        <el-table-column min-width="140" prop="girl_equip_name" label="女装备名称" />
        <el-table-column min-width="140" prop="base_rate" label="基础概率(万分)" />
        <el-table-column width="180" fixed=right label="操作">
          <template #default="scope">
            <el-button type="primary" @click="openForm(scope.row)">编辑</el-button>
            <el-button type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <updateForm ref="updateFormRef" :gameList="action.gameList" @update-list="getList" />
  </div>
</template>

<style lang='scss' scoped>

</style>
